package ru.ifmo.ctd.intsys.afanasyeva.neural;

import java.io.PrintWriter;
import java.util.Arrays;

class NonLinearPerceptron {
	private double[] weights;
	
	public void print(PrintWriter writer) {
		for (double w : weights) {
			writer.print(w + " ");
		}
	}
	
	public void load(String string) {
		String[] array = string.split(" ");
		for (int i = 0; i < array.length; i++) {
			weights[i] = Double.parseDouble(array[i]);
		}
	}
	
	public NonLinearPerceptron (int inputCount) {
		weights = new double[inputCount];
		reset();
	}
	
	public void reset() {
		Arrays.fill(weights, Math.random());
		//Arrays.fill(weights, (double) 1 / weights.length);
	}
	
	public int getInputCount() {
		return weights.length;
	}
	
	public double getWeight(int i) {
		return weights[i];
	}
	
	void setWeight(int i, double value) {
		weights[i] = value;
	}
	
	public double getOutput(double[] input) {
		double sum = 0;
		for (int i = 0; i < input.length; i++) {
			sum += weights[i] * input[i];
		}
		return 1.0 / (1.0 + Math.exp(-sum));
	}
}
